home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- Copyright (c) 2008 Ensolis, LLC. All Rights Reserved.
- ----------------------------------------------------------------------------*/
-
- // constants
- const FF_TIME_NIGHT = -1; // time that night switches to day
- const FF_TIME_DAY = 15; // time that day switches to night
- const FF_TIMER = 90*1000; // one minute 30 second timer
- const ffIErrorItem = Components.interfaces.ffIErrorItem;
-
- //global forecastfox object
- var gForecastfox = null;
-
- function ffLoad()
- {
- gForecastfox = new Forecastfox();
- gForecastfox.start();
- }
-
- function ffUnload()
- {
- gForecastfox.stop();
- gForecastfox = null;
- }
-
- ///////////////////////
- // Forecastfox Object
- function Forecastfox() {}
- Forecastfox.prototype = {
- _manager: null,
- _bundle: null,
- _prefixes: null,
- _timer: null,
-
- start: function Forecastfox_start()
- {
- //get our XPCOM manager service
- var obs = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- this._manager = Components.classes["@ensolis.com/forecastfox/manager-service;1"].getService(Components.interfaces.ffIManagerService);
- this._bundle = document.getElementById("ff-bundle");
-
- //setup object
- this._prefixes = {};
- this._prefixes["cc"] = "current";
- this._prefixes["dayf"] = "forecast";
- this._prefixes["dayt"] = "forecast";
-
- //add observer to forecastfox:update
- obs.addObserver(this, "forecastfox-manager", false);
-
- //setup display - give window a chance to display before loading
- var comp = this;
- if (!this._manager.isRunning)
- window.setTimeout(function() { comp._manager.run(false); }, 500);
- else
- window.setTimeout(function() { comp._update("display"); }, 500);
- },
-
- stop: function Forecastfox_stop()
- {
- try {
- //remove observers
- var obs = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- obs.removeObserver(this, "forecastfox-manager");
- obs = null;
- } catch(e) {}
-
- // clear progress timer
- if (this._timer) {
- window.clearTimeout(this._timer);
- this._timer = null;
- }
-
- //destroy variables
- this._manager = null;
- this._bundle = null;
- this._prefixes = null;
- },
-
- observe: function Forecastfox_observe(aSubject, aTopic, aData)
- {
- var comp = this;
- window.setTimeout(function() { comp._update(aData); }, 0);
- },
-
- hideContext: function Forecastfox_hideContext()
- {
- var node = document.getElementById("ff-popup");
- node.hidePopup();
- },
-
- addIcons: function Forecastfox_addIcons(aEvent)
- {
- var icnSvc = this._manager.icons;
- var node = aEvent.target;
-
- //remove old elements
- while (node.hasChildNodes() && node.lastChild.tagName != "menuseparator")
- node.removeChild(node.lastChild);
-
- //get icons
- var items = icnSvc.getItems({});
- var id = icnSvc.current.ID;
-
- //set none
- var item;
- if (items.length == 0) {
- item = document.createElement("menuitem");
- item.setAttribute("label", this._bundle.getString("ff.icons.none"));
- item.setAttribute("disabled", true);
- node.appendChild(item);
- return;
- }
-
- //set for one or more
- for (var i=0; i<items.length; i++) {
- item = document.createElement("menuitem");
- item.setAttribute("label", items[i].name);
- item.setAttribute("value", items[i].ID);
- item.setAttribute("type", "radio");
- item.setAttribute("name", "icon");
- if (items[i].ID == id)
- item.setAttribute("checked", "true");
- node.appendChild(item);
- }
- },
-
- selectIcon: function Forecastfox_selectIcon(aEvent)
- {
- var icnSvc = this._manager.icons;
-
- //set if not current
- var node = aEvent.target;
- var id = node.getAttribute("value");
- if (id != icnSvc.current.ID && id != "ff-icons-more")
- icnSvc.current = icnSvc.getItem(id);
-
- node.parentNode.hidePopup();
- },
-
- addProfiles: function Forecastfox_addProfiles(aEvent)
- {
- var prfSvc = this._manager.profiles;
- var node = aEvent.target;
-
- //remove old elements
- while (node.hasChildNodes() && node.lastChild.tagName != "menuseparator")
- node.removeChild(node.lastChild);
-
- //get profiles
- var items = prfSvc.getItems({});
- var id = prfSvc.current.ID;
-
- //set none
- var item;
- if (items.length == 0) {
- item = document.createElement("menuitem");
- item.setAttribute("label", this._bundle.getString("ff.profiles.none"));
- item.setAttribute("disabled", true);
- node.appendChild(item);
- return;
- }
-
- //set for one or more
- for (var i=0; i<items.length; i++) {
- item = document.createElement("menuitem");
- item.setAttribute("label", items[i].name);
- item.setAttribute("type", "radio");
- item.setAttribute("name", "profile");
- item.setAttribute("value", items[i].ID);
- if (items[i].ID == id)
- item.setAttribute("checked", "true");
- node.appendChild(item);
- }
- },
-
- selectProfile: function Forecastfox_selectProfile(aEvent)
- {
- var prfSvc = this._manager.profiles;
-
- //set if not current
- var node = aEvent.target;
- var id = node.getAttribute("value");
- if (id != prfSvc.current.ID)
- prfSvc.current = prfSvc.getItem(id);
-
- node.parentNode.hidePopup();
- },
-
- clickLink: function Forecastfox_clickLink(aEl, event)
- {
- //middle clicked
- if (event.button == 1) {
-
- //do oncommand
- eval(aEl.getAttribute("oncommand"));
- }
- },
-
- openLink: function Forecastfox_openLink(aEvent, aUnits, aPartner, aFrom)
- {
- // supply an aOpenEvent and it will be used in the openUILink instead of the aEvent
- var url = aEvent.target.getAttribute("url");
- if (url == "") {
- url = this._bundle.getString("ff.url.default");
- aPartner = true;
- aUnits = false;
- }
-
- var separator = (url.indexOf("?") != -1) ? "&" : "?";
- if (aPartner)
- url += separator + "partner=" + this._manager.partner;
- if (aUnits) {
- separator = (url.indexOf("?") != -1) ? "&" : "?";
- url += separator + "metric=" + this._manager.getPref("units.current");
- }
-
- this._manager.openLink(url, this._getWhere(aEvent, aFrom));
- },
-
- importDOM: function Forecastfox_importDOM()
- {
- var success = this._manager.migrator.importDOM(window);
- var prompter = this._getPrompter(window);
- if (!success) {
- var err = this._manager.migrator.lastError;
- if (err.severity < ffIErrorItem.SEVERITY_ERROR)
- return;
- prompter.alert(err.name, err.message);
- } else
- prompter.alert(this._bundle.getString("ff.import.title"),
- this._bundle.getString("ff.import.success"));
- },
-
- exportDOM: function Forecastfox_exportDOM()
- {
- var success = this._manager.migrator.exportDOM(window);
- var prompter = this._getPrompter(window);
- if (!success) {
- var err = this._manager.migrator.lastError;
- if (err.severity < ffIErrorItem.SEVERITY_ERROR)
- return;
- prompter.alert(err.name, err.message);
- } else
- prompter.alert(this._bundle.getString("ff.export.title"),
- this._bundle.getString("ff.export.success"));
- },
-
- _setOrient: function Forecastfox__setOrient(aOrient)
- {
- //element that need set
- var ids = ["ff-box", "ff-weather", "ff-data-box", "ff-current-box", "ff-spacer",
- "ff-forecast-box", "ff-today-panel", "ff-forecast-panel"];
-
- //set attribute
- for (var x=0; x<ids.length; x++)
- document.getElementById(ids[x]).setAttribute("orient", aOrient);
- },
-
- _getWhere: function Forecastfox__getWhere(aEvent, aFrom)
- {
- //get left click default where
- var where = this._manager.getPref("links." + aFrom);
-
- //get link modifier
- try {
- var pbs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
- var appBranch = pbs.getBranch(null);
- var background = appBranch.getBoolPref("browser.tabs.loadInBackground");
- } catch(e) {
- background = false;
- }
-
- //determine if middle click
- var middle = (aEvent.button == 1);
-
- //get keys pressed
- var ctrl = aEvent.ctrlKey;
- var shift = aEvent.shiftKey;
-
- //do key based modifiers
- if (ctrl || middle) {
- if (shift || background)
- where = "tabshifted";
- else
- where = "tab";
- } else if (shift)
- where = "window";
-
- return where;
- },
-
- _moveBox: function Forecastfox__moveBox()
- {
- //check if box is in the right location
- var toolbar = document.getElementById(this._manager.getPref("general.bar"));
- var box = document.getElementById("ff-box");
- var position = this._manager.getPref("general.position");
-
- //if toolbar doesn't exist move to default location
- if (!toolbar) {
- this._manager.setPref("general.bar", "status-bar");
- this._manager.setPref("general.position", -1);
- return;
- }
-
- // set the orientation
- var orient = document.defaultView.getComputedStyle(toolbar, "").getPropertyValue("-moz-box-orient");
- this._setOrient(orient);
-
- // bail if it is in the right place
- if (this._indexOf(toolbar,box) == position)
- return;
-
- //remove us from parent
- box.parentNode.removeChild(box);
-
- //make sure we have the right element type
- var newbox = null;
- if (toolbar.localName == "statusbar") {
- if (box.localName != "statusbarpanel")
- newbox = document.createElement("statusbarpanel");
- } else {
- if (box.localName == "statusbarpanel")
- newbox = document.createElement("hbox");
- }
-
- //append children of old box
- if (newbox) {
- newbox.setAttribute("id", "ff-box");
- while (box.hasChildNodes())
- newbox.appendChild(box.firstChild);
- } else
- newbox = box;
-
- //insert us in correct place
- this._insertAtIndex(toolbar, newbox, position);
- },
-
- _indexOf: function Forecastfox__indexOf(aParent, aChild)
- {
- // -1 if it does not exist
- var children = aParent.childNodes;
- for (var x=0; x<children.length; x++) {
- if (children[x] == aChild)
- return (x == children.length - 1) ? -1 : x;
- }
- return null;
- },
-
- _insertAtIndex: function Forecastfox__insertAtIndex(aParent, aChild, aIndex)
- {
- var children = aParent.childNodes;
- if ((children.length == 0) || (aIndex >= children.length) || (aIndex < 0))
- aParent.appendChild(aChild);
- else
- aParent.insertBefore(aChild, children[aIndex]);
- },
-
- _update: function Forecastfox__update(aMethod)
- {
- var err;
-
- //update all
- if (aMethod == "display") {
- this._update("startUpdate");
- this._update("endUpdate");
- }
-
- //check for an error
- if (aMethod == "endUpdate") {
- err = this._manager.lastError;
- if (err.severity != ffIErrorItem.SEVERITY_INFO) {
- this._update("startUpdate");
- this._update("lastError");
- return;
- }
- }
-
- //move box
- this._moveBox();
-
- //remove progress and errors
- this._removeIndicator();
-
- //now do update
- switch (aMethod) {
- case "startUpdate":
- this._showIndicator("progress");
- break;
- case "lastError":
- this._showIndicator("error");
- break;
- case "endUpdate":
- default:
- this._showData();
- this._showCurrent();
- this._showForecast();
- break;
- }
-
- // set the borders
- this._borders();
- },
-
- _removeIndicator: function Forecastfox__removeIndicator()
- {
- var item = document.getElementById("ff-indicator");
-
- // clear the progress timer
- if (this._timer) {
- window.clearTimeout(this._timer);
- this._timer = null;
- }
-
- //remove the indicator
- item.removeAttribute("tooltiptext");
- item.removeAttribute("label");
- item.removeAttribute("src");
- item.removeAttribute("type");
- item.setAttribute("collapsed", true);
- },
-
- _showIndicator: function Forecastfox__showIndicator(type)
- {
- var item = document.getElementById("ff-indicator");
- item.setAttribute("type", type);
-
- switch (type) {
-
- //set error
- case "error":
- var err = this._manager.lastError;
- item.setAttribute("label", err.name);
- item.setAttribute("tooltiptext", err.message);
- item.setAttribute("src", "chrome://global/skin/icons/error-16.png");
- break;
-
- // set the progress
- case "progress":
- item.removeAttribute("label");
- item.setAttribute("tooltiptext", this._bundle.getString("ff.tooltip.loading"));
- item.setAttribute("src", "chrome://global/skin/icons/loading_16.png");
- var self = this;
- this._timer = window.setTimeout(function() { self._showIndicator("timer"); }, FF_TIMER);
- break;
-
- // set the timer message
- case "timer":
- this._timer = null;
- item.setAttribute("label", this._bundle.getString("ff.manager.timeout.name"));
- item.setAttribute("tooltiptext", this._bundle.getString("ff.manager.timeout.name"));
- item.setAttribute("src", "chrome://global/skin/icons/warning-16.png");
- break;
-
- default:
- return;
- }
-
- //show panel
- item.removeAttribute("collapsed");
- },
-
- _showData: function Forecastfox_showData() {
- var swa = this._getItem("swa", "panel");
- var logo = this._getItem("logo", "panel");
- var hbh = this._getItem("hbh", "panel");
- var hbh_menu = this._getItem("popup", "hbh");
- var fiveday = this._getItem("fiveday", "panel");
- var fiveday_menu = this._getItem("popup", "fiveday");
-
- //remove tooltip and attributes
- this._evictImages(swa);
- this._evictImages(logo);
- this._evictImages(hbh);
- this._evictImages(fiveday);
- swa.removeAttribute("src");
- swa.removeAttribute("label");
- logo.removeAttribute("src");
- logo.removeAttribute("label");
- hbh.removeAttribute("src");
- hbh.removeAttribute("label");
- fiveday.removeAttribute("src");
- fiveday.removeAttribute("label");
-
- //do swa
- if (!this._manager.getPref("swa.panel.enabled") || this._manager.parser.getValue("swa", 0, "active", null) != "true")
- swa.setAttribute("collapsed", "true");
- else {
- this._setPanel(swa, "swa", "swa", null);
- swa.setAttribute("url", this._manager.parser.getValue("swa", 0, "url", null));
- swa.removeAttribute("collapsed");
- }
-
- // set logo
- logo.setAttribute("collapsed", "true");
- var url = this._manager.parser.getValue("logo", 0, "url", null);
- if (false && url && url != "N/A") {
- logo.setAttribute("url", url);
- logo.setAttribute("src", this._manager.parser.getValue("logo", 0, "imagepath", null));
- logo.setAttribute("tooltipenabled", "true");
- logo.setAttribute("tooltipdisplay", "0");
- logo.setAttribute("tooltipsrc", this._manager.parser.getValue("logo", 0, "tooltippath", null));
- logo.setAttribute("tooltipwidth", this._manager.parser.getValue("logo", 0, "tooltipwidth", null));
- logo.setAttribute("tooltipheight", this._manager.parser.getValue("logo", 0, "tooltipheight", null));
- logo.setAttribute("prefix", "logo");
- logo.setAttribute("tooltiplabel", "");
- logo.setAttribute("tooltiptitle", "");
- logo.setAttribute("tooltip", "ff-tooltip");
- logo.removeAttribute("collapsed");
- FFTracker.trackURL(this._manager.parser.getValue("logo", 0, "track", null));
- }
-
- // set hbh
- hbh.setAttribute("collapsed", "true");
- hbh_menu.setAttribute("hidden", "true");
- url = this._manager.parser.getValue("days", 0, "hbh", null);
- if (url && url != "N/A") {
- hbh_menu.setAttribute("url", url);
- hbh_menu.removeAttribute("hidden");
- }
- if (this._manager.getPref("hbh.panel.enabled") && url && url != "N/A") {
- hbh.setAttribute("url", url);
- hbh.setAttribute("src", "chrome://forecastfox/skin/images/hbh.png");
- hbh.setAttribute("tooltipenabled", "true");
- hbh.setAttribute("tooltipdisplay", "1");
- hbh.setAttribute("tooltipsrc", "");
- hbh.setAttribute("prefix", "hbh");
- hbh.setAttribute("tooltiplabel", this._bundle.getString("ff.hbh.title"));
- hbh.setAttribute("tooltiptitle", "");
- hbh.setAttribute("tooltip", "ff-tooltip");
- hbh.removeAttribute("collapsed");
- }
-
- // set fiveday
- fiveday.setAttribute("collapsed", "true");
- fiveday_menu.setAttribute("hidden", "true");
- url = this._manager.parser.getValue("days", 0, "url5day", null);
- if (url && url != "N/A") {
- fiveday_menu.setAttribute("url", url);
- fiveday_menu.removeAttribute("hidden");
- }
- if (this._manager.getPref("fiveday.panel.enabled") && url && url != "N/A") {
- fiveday_menu.setAttribute("url", url);
- fiveday.setAttribute("url", url);
- fiveday.setAttribute("src", "chrome://forecastfox/skin/images/5day.png");
- fiveday.setAttribute("tooltipenabled", "true");
- fiveday.setAttribute("tooltipdisplay", "1");
- fiveday.setAttribute("tooltipsrc", "");
- fiveday.setAttribute("prefix", "fiveday");
- fiveday.setAttribute("tooltiplabel", this._bundle.getString("ff.fiveday.title"));
- fiveday.setAttribute("tooltiptitle", "");
- fiveday.setAttribute("tooltip", "ff-tooltip");
- fiveday.removeAttribute("collapsed");
- }
- },
-
- _showCurrent: function Forecastfox__showCurrent()
- {
- var current = this._getItem("current", "panel");
- var radar = this._getItem("radar", "panel");
-
- //remove tooltip and attributes
- this._evictImages(current);
- this._evictImages(radar);
- current.removeAttribute("src");
- current.removeAttribute("label");
- radar.removeAttribute("src");
- radar.removeAttribute("label");
-
- //do current
- if (!this._manager.getPref("cc.panel.enabled"))
- current.setAttribute("collapsed", "true");
- else {
- this._setPanel(current, "cc", null, null);
- current.setAttribute("url", this._manager.parser.getValue("current", 0, "url", null));
- current.removeAttribute("collapsed");
- }
-
- //do radar
- if (!this._manager.getPref("radar.panel.enabled"))
- radar.setAttribute("collapsed", "true");
- else {
- this._setPanel(radar, "radar", "radar", null);
-
- radar.setAttribute("url", this._manager.parser.getValue("radar", 0, "url", null));
-
- // only display the radar node if there is radar
- var image = this._manager.parser.getValue("radar", 0, "image", null);
- if (image && image != "N/A")
- radar.removeAttribute("collapsed");
- else
- radar.setAttribute("collapsed", true);
- }
- },
-
- _showForecast: function Forecastfox__showForecast()
- {
- var today = this._getItem("today", "panel");
- var extended = this._getItem("forecast", "panel");
-
- //remove tooltip and attributes
- while (today.hasChildNodes()) {
- this._evictImages(today.lastChild);
- today.lastChild.removeAttribute("src");
- today.lastChild.removeAttribute("label");
- today.removeChild(today.lastChild);
- }
- while (extended.hasChildNodes()) {
- this._evictImages(extended.lastChild);
- extended.lastChild.removeAttribute("src");
- extended.lastChild.removeAttribute("label");
- extended.removeChild(extended.lastChild);
- }
-
- //set url for popup menu since it is the same for all forecast days
- var menu = document.getElementById("ff-popup-forecast");
- menu.setAttribute("url", this._manager.parser.getValue("days", 0, "url", null));
-
- //do today
- if (!this._manager.getPref("dayt.panel.enabled") || (this._manager.getPref("dayt.panel.mode") < 0))
- today.setAttribute("collapsed", "true");
- else
- this._updateToday(today);
-
- //do extended
- if (!this._manager.getPref("dayf.panel.enabled") || (this._manager.getPref("dayf.panel.days") == 0))
- extended.setAttribute("collapsed", "true");
- else
- this._updateExtended(extended);
- },
-
- _updateToday: function Forecastfox__updateToday(aNode)
- {
- var mode = this._manager.getPref("dayt.panel.mode");
- var sw_mode = this._manager.getPref("dayt.panel.switch");
- var panels = (mode == 2) ? 2 : 1;
- var cHours = this._getHour();
- var day_index = 0;
-
- while (this._shouldIncDay(day_index, cHours))
- day_index++;
-
- for (var x = 0; x < panels; x++) {
-
- if (cHours <= FF_TIME_NIGHT || cHours >= FF_TIME_DAY) {
- if (mode == 0 && sw_mode == 1)
- day_index++;
- else if (mode == 2)
- panels--;
- }
-
- if (this._shouldCreatePanel("today", "days", x, cHours))
- this._createPanel("today", aNode, "days", day_index);
- else if (this._shouldCreatePanel("today", "nights", x, cHours))
- this._createPanel("today", aNode, "nights", day_index);
- }
-
- // show the box!
- aNode.removeAttribute("collapsed");
- },
-
- _updateExtended: function Forecastfox__updateExtended(aNode)
- {
- var days = this._manager.getPref("dayf.panel.days");
- var new_panel = false;
- var cHours = this._getHour();
- var day_index = 1;
- var day_add = 0;
-
- while (this._shouldIncDay(day_add, cHours))
- day_add++;
-
- day_index += day_add;
-
- for (var x = 0; x < days; day_index++) {
- // finish if we went through too many days
- if (day_index > 8)
- break;
-
- try {
- // create the corresponding nodes
- if (this._shouldCreatePanel("extended", "days", day_index, cHours))
- new_panel = this._createPanel("extended", aNode, "days", day_index);
- } catch (e) {}
-
- try {
- if (this._shouldCreatePanel("extended", "nights", day_index, cHours))
- new_panel = this._createPanel("extended", aNode, "nights", day_index);
- } catch (e) {}
-
- // increase x if we made a new one
- if (new_panel)
- x++;
-
- new_panel = false;
- }
-
- aNode.removeAttribute("collapsed");
- },
-
- _shouldIncDay: function Forecastfox__shouldIncDay(aIndex, aHours)
- {
- return ((aHours < 12 && !this._hasData(aIndex)) &&
- (FF_TIME_NIGHT < aHours && aHours < FF_TIME_DAY));
- },
-
- _hasData: function Forecastfox__hasData(aIndex)
- {
- return ((this._manager.parser.getValue("days", aIndex, "t", null) != "N/A") ||
- (this._manager.parser.getValue("days", aIndex, "tlong", null) != "N/A"));
- },
-
- _shouldCreatePanel: function Forecastfox__shouldCreatePanel(aType, aPart, aIndex, aHours)
- {
- var mode, sw_mode, cHours, t_mode, t_sw_mode, t_on;
- switch (aType) {
- case "today":
- mode = this._manager.getPref("dayt.panel.mode");
- sw_mode = this._manager.getPref("dayt.panel.switch");
-
- switch (aPart) {
- case "days":
- if (aHours > FF_TIME_NIGHT && aHours < FF_TIME_DAY)
- return ((mode == 0) || (mode == 2 && aIndex == 0));
- else
- return ((mode == 0 && sw_mode == 1) || (mode == 2 && aIndex == 2));
- case "nights":
- if (mode == 1)
- return true;
- else if (aHours > FF_TIME_NIGHT && aHours < FF_TIME_DAY)
- return (mode == 2 && aIndex == 1);
- else
- return ((mode == 0 && sw_mode == 0) || (mode == 2));
- }
- break;
- case "extended":
- mode = this._manager.getPref("dayf.panel.mode");
- t_mode = this._manager.getPref("dayt.panel.mode");
- t_sw_mode = this._manager.getPref("dayt.panel.switch");
- t_on = this._manager.getPref("dayt.panel.enabled");
-
- switch (aPart) {
-
- case "nights":
- return ((mode == 1) || (mode == 2));
- case "days":
- // if we're displaying days or days and nights
- if (mode == 0 || mode == 2) {
- // If its between the "days" hours
- if (FF_TIME_NIGHT < aHours && aHours < FF_TIME_DAY)
- return true;
- // If its between the "nights" hours
- else
- return ((t_mode != 0) || (!t_on || (aIndex != 1 && t_sw_mode == 1)) || (t_sw_mode != 1));
- }
- else
- return false;
- }
- break;
- }
-
- return false;
- },
-
- _createPanel: function Forecastfox__createPanel(aGroup, aParent, aPart, aDay)
- {
- var node = document.createElement("ffpanel");
- var prefix = (aGroup == "extended") ? "dayf" : "dayt";
-
- //set context menu on node
- node.setAttribute("context","ff-popup");
- node.setAttribute("id", "forecast" + aPart + aDay);
- node.setAttribute("url", this._manager.parser.getValue(aPart, aDay, "url", null));
- node.setAttribute("tooltip", "ff-tooltip");
- node.setAttribute("tooltipad", "false");
-
- //set panel and append
- this._setPanel(node, prefix, aPart, aDay);
- aParent.appendChild(node);
-
- // return that one was made
- return true;
- },
-
- _getItem: function Forecastfox__getItem(aItem, aType)
- {
- var item = null;
- item = document.getElementById("ff-" + aItem + "-" + aType);
- return item;
- },
-
- _getHour: function Forecastfox__getHour()
- {
- var time = this._manager.parser.getValue("global", 0, "tm", null);
- var ind = time.indexOf(":");
- if (ind < 0) {
- time = Number(this._manager.getPref("general.last"));
- return (new Date(time)).getHours();
- }
- return Number(time.substring(0,ind));
- },
-
- _setPanel: function Forecastfox__setPanel(aNode, aPrefix, aGroup, aIndex)
- {
- //if group isn't provided get from prefix
- if (!aGroup)
- aGroup = this._prefixes[aPrefix];
-
- //set tooltip
- this._setTooltip(aNode, aPrefix, aGroup, aIndex);
-
- //set display
- var icon = this._manager.parser.getValue(aGroup, aIndex, "icon", null);
- var label = this._manager.parser.getLabel(this._manager.getPref(aPrefix + ".panel.label"), aGroup, aIndex);
- icon = this._manager.icons.current.getItem(icon + "-small");
- var width = icon.width;
- var height = icon.height;
- switch (this._manager.getPref(aPrefix + ".panel.display")) {
- case 1:
- aNode.setAttribute("label", label);
- aNode.setAttribute("crop", "right");
- break;
- case 2:
- aNode.setAttribute("src", icon.URL);
- if (width)
- aNode.setAttribute("imagewidth", width);
- if (height)
- aNode.setAttribute("imageheight", height);
- aNode.setAttribute("label", label);
- aNode.setAttribute("crop", "right");
- break;
- case 0:
- default:
- aNode.setAttribute("src", icon.URL);
- if (width)
- aNode.setAttribute("imagewidth", width);
- if (height)
- aNode.setAttribute("imageheight", height);
- break;
- }
- },
-
- _setTooltip: function Forecastfox__setTooltip(aNode, aPrefix, aGroup, aIndex)
- {
- //if group isn't provided get from prefix
- if (!aGroup)
- aGroup = this._prefixes[aPrefix];
-
- //get the tooltip enabled and display prefs
- var enabled = this._manager.getPref(aPrefix + ".tooltip.enabled");
- var display = this._manager.getPref(aPrefix + ".tooltip.display");
-
- //get icon attributes
- var icon = this._manager.parser.getValue(aGroup, aIndex, "icon", null);
- icon = this._manager.icons.current.getItem(icon + "-large");
- var src = icon.URL;
- var width = icon.width;
- var height = icon.height;
-
- //get the label attributes
- var label = this._manager.getPref(aPrefix + ".tooltip.label");
- label = this._manager.parser.getLabel(label, aGroup, aIndex);
- var title = this._manager.getPref(aPrefix + ".tooltip.title");
- title = this._manager.parser.getLabel(title, aGroup, aIndex);
-
- //set the attributes on the node
- aNode.setAttribute("tooltipenabled", String(enabled));
- aNode.setAttribute("tooltipdisplay", String(display));
- aNode.setAttribute("tooltipsrc", String(src));
- aNode.setAttribute("prefix", aPrefix);
- if (width)
- aNode.setAttribute("tooltipwidth", String(width));
- if (height)
- aNode.setAttribute("tooltipheight", String(height));
- aNode.setAttribute("tooltiptitle", title);
- aNode.setAttribute("tooltiplabel", label);
- aNode.setAttribute("tooltip", "ff-tooltip");
- },
-
- _borders: function Forecastfox__borders()
- {
- //get elements
- var spacer = document.getElementById("ff-spacer");
- var today = this._getItem("today", "panel");
- var extended = this._getItem("forecast", "panel");
- var radar = this._getItem("radar", "panel");
- var swa = this._getItem("swa", "panel");
- var current = this._getItem("current", "panel");
-
- var showing = new Object();
-
- //determine what is showing
- showing["current"] = (this._manager.getPref("cc.panel.enabled") && !current.hasAttribute("collapsed"));
- showing["radar"] = (this._manager.getPref("radar.panel.enabled") && !radar.hasAttribute("collapsed"));
- showing["swa"] = (this._manager.getPref("swa.panel.enabled") && !swa.hasAttribute("collapsed"));
- showing["today"] = (this._manager.getPref("dayt.panel.enabled") && today.hasChildNodes() && !today.hasAttribute("collapsed"));
- showing["extended"] = (this._manager.getPref("dayf.panel.enabled") && extended.hasChildNodes() && !extended.hasAttribute("collapsed"));
-
- //show-hide spacer
- var cShowing = (showing["current"] || showing["radar"] || showing["swa"]);
- var fShowing = (showing["today"] || showing["extended"]);
- if (cShowing && fShowing)
- spacer.removeAttribute("collapsed");
- else
- spacer.setAttribute("collapsed", "true");
-
- //remove old first-last attribute
- var box = document.getElementById("ff-box");
- var panels = box.getElementsByTagName("ffpanel");
- for (var x=0; x<panels.length; x++) {
- panels[x].removeAttribute("ff-first");
- panels[x].removeAttribute("ff-last");
- }
-
- //set first attribute
- if (showing["swa"])
- swa.setAttribute("ff-first", "true");
- else if (showing["radar"])
- radar.setAttribute("ff-first", "true");
- else if (showing["current"])
- current.setAttribute("ff-first", "true");
- else if (showing["today"])
- today.firstChild.setAttribute("ff-first", "true");
- else if (showing["extended"])
- extended.firstChild.setAttribute("ff-first", "true");
-
- //set last attribute
- if (showing["extended"])
- extended.lastChild.setAttribute("ff-last", "true");
- else if (showing["today"])
- today.lastChild.setAttribute("ff-last", "true");
- else if (showing["current"])
- current.setAttribute("ff-last", "true");
- else if (showing["radar"])
- radar.setAttribute("ff-last", "true");
- else if (showing["swa"])
- swa.setAttribute("ff-last", "true");
- },
-
- _evictImages: function Forecastfox__evictImages(aNode)
- {
- //remove the source image
- var image = aNode.getAttribute("src");
- if (image != "")
- this._manager.evictImage(image);
-
- //remove the tooltip source image
- image = aNode.getAttribute("tooltipsrc");
- if (image != "")
- this._manager.evictImage(image);
- },
-
- _getPrompter: function Forecastfox__getPrompter(aParent)
- {
- //get the watcher service
- var watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
- getService(Components.interfaces.nsIWindowWatcher);
-
- //return a prompter
- return watcher.getNewPrompter(aParent);
- },
-
- openDialog: function Forecastfox_openDialog(aType)
- {
- //focus the window if already open
- var mediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].
- getService(Components.interfaces.nsIWindowMediator);
- var win = mediator.getMostRecentWindow(aType);
- if (win) {
- win.focus();
- return;
- }
-
- //open a new window
- switch (aType) {
- case "forecastfox:options":
- window.openDialog("chrome://forecastfox/content/options/options.xul", "options", "chrome");
- break;
-
- case "forecastfox:about":
- window.openDialog("chrome://forecastfox/content/about.xul", "ff-about", "chrome");
- break;
- default:
- break;
- }
- }
- };